﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using sydfdl.TMS.Model;
using sydfdl.TMS.Tool;

namespace sydfdl.TMS.BLL
{
    public class BLLT_B_Notice
    {
        public T_Base<T_B_Notice> GetList(string xml)
        {
            T_Base<T_B_Notice> list = new T_Base<T_B_Notice>();
            SqlParameter[] para = { 
                                  new SqlParameter("@para",SqlDbType.Xml,-1)
                                  };
            para[0].Value = xml;
            #region 获取数据
            using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.tmsConn, CommandType.StoredProcedure, @"P_B_GetAD", para))
            {
                List<T_B_Notice> inner = new List<T_B_Notice>();
                if (dr.Read() && dr.HasRows)
                    list.total = dr.GetInt32(0);
                if (dr.NextResult())
                {
                    while (dr.Read() && dr.HasRows)
                    {
                        T_B_Notice dto = new T_B_Notice();
                        dto.NID = dr.GetGuid(0);
                        dto.NName = dr.GetString(1);
                        dto.NContentMark = dto.NContent = dr.GetString(2);
                        dto.NBit = dr.GetBoolean(3);
                        dto.STime = dr.GetDateTime(4);
                        dto.ETime = dr.GetDateTime(5);
                        dto.NTime = dr.GetDateTime(6);
                        inner.Add(dto);
                    }
                    list.data = inner;
                }
            }
            #endregion
            return list;
        }

        /// <summary>
        /// 操作数据
        /// </summary>
        /// <param name="xml">第一个为添加 ；第二个为修改；第三个为删除；</param>
        /// <returns></returns>
        public string Save(params IEnumerable<T_B_Notice>[] xml)
        {
            string addXmL = EFHelp<T_B_Notice>.GetXML(xml[0]);
            string editXML = EFHelp<T_B_Notice>.GetXML(xml[1]);
            string delXML = EFHelp<T_B_Notice>.GetXML(xml[2]);
            SqlParameter[] para = { 
                                  new SqlParameter("@addXmL",SqlDbType.Xml,-1),
                                  new SqlParameter("@editXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@delXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@userXML",SqlDbType.Xml,-1),
                                  new SqlParameter("@ReturnValue",SqlDbType.VarChar,100)
                                  };
            para[0].Value = addXmL;
            para[1].Value = editXML;
            para[2].Value = delXML;
            para[3].Value = null;
            para[4].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.tmsConn, CommandType.StoredProcedure, @"P_B_SaveAD", para);
            return (para[4].Value ?? string.Empty).ToString();
        }
    }
}
